# -*- coding: utf-8 -*-

'''eof
name:申请人关联关系校验
code:R69_PersonalRelationlistCheck_WHB
tableName:
columnName:
groups:强规则>关联关系校验
dependencies:WDXT_Black,WDXT_RelationBlack
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import pandas as pd
import json
from datetime import datetime


reload(sys)
sys.setdefaultencoding('utf-8')
null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']


def checkBlack(base, baseName, blackList):
    if base in null_type_list:
        return "获取到的数据为空"
    try:
        code = base["sysHead"]["responseCode"]
    except:
        return "接口获取失败"
    if code == "0":
        try:
            blackInfo = base.get("body").get(baseName)
        except:
            return "接口获取失败"
        if blackInfo not in null_type_list and isinstance(blackInfo, list):
            if len(blackInfo) >= 1:
                flag = False
                for black in blackInfo:
                    certId = black.get("CERTID")
                    if certId not in null_type_list and certId in blackList:
                        return 0
                    elif certId in null_type_list:
                        flag = True
                if flag:
                    return "接口数据异常"
                return 1
            else:
                return 1
        else:
            return "接口数据异常"
    else:
        return "接口获取失败"


def getRule49():
    certIdList = []
    legalPersonIdCard = ratingRequest.get("legalPersonIdCard")
    if legalPersonIdCard not in null_type_list:
        certIdList.append(legalPersonIdCard)
    else:
        raise RuntimeError("身份证号为空，无法判断个人黑名单")
    blackResult = checkBlack(WDXT_RelationBlack, "RELATIONSHIPDATAS", certIdList)
    if blackResult == 0:
        return 0
    elif blackResult != 1:
        raise RuntimeError(blackResult)
    else:
        return 1



result = getRule49()

